Choosing a Species
obs_csv <- file.path(dir_data, "obs.csv")
obs_geo <- file.path(dir_data, "obs.geojson")
# get species occurrence data from GBIF with coordinates
(res <- spocc::occ(
limit = 10000,
query = 'Betula lenta',
from = 'gbif', has_coords = T))
## Searched: gbif
## Occurrences - Found: 2,666, Returned: 2,666
## Search type: Scientific
## gbif: Betula lenta (2666)
# extract data frame from result
df <- res$gbif$data[[1]]
count <- nrow(df) # number of rows
count
## [1] 2666
View Results
# convert to points of observation from lon/lat columns in data frame
obs <- df %>%
sf::st_as_sf(
coords = c("longitude", "latitude"),
crs = st_crs(4326)) %>%
select(1,27:60, 163)
readr::write_csv(df, obs_csv)
sf::write_sf(obs, obs_geo)
## Warning in CPL_write_ogr(obj, dsn, layer, driver,
## as.character(dataset_options), : GDAL Error 6: DeleteLayer() not supported by
## this dataset.
# show points on map
mapview::mapview(obs, map.types = "OpenTopoMap")
Question 1: How many observations total are in GBIF for your species? (Hint: ?occ)
Question 2. Do you see any odd observations, like marine species on land or vice versa? If so, please see the Data Cleaning and explain what you did to fix or remove these points.